package org.bai.algorithm.day01;

import java.util.Stack;

/**
 * @ClassName CQueue
 * @Description <a href="https://leetcode-cn.com/problems/yong-liang-ge-zhan-shi-xian-dui-lie-lcof/submissions/">两个栈实现队列</a>
 * @Author bai
 * @Date 2021/8/9 23:16
 * @Version 1.0
 **/
public class CQueue {

    private Stack<Integer> stack1;
    private Stack<Integer> stack2;

    public CQueue() {
        stack1 = new Stack<>();
        stack2 = new Stack<>();
    }

    public void appendTail(int value) {
        while (!stack2.isEmpty()) {
            stack1.push(stack2.pop());
        }
        stack1.push(value);
    }

    public int deleteHead() {
        while (!stack1.isEmpty()) {
            stack2.push(stack1.pop());
        }
        if (!stack2.isEmpty()) {
            return stack2.pop();
        } else {
            return -1;
        }
    }

}
